package com.atguigu.gmall.user.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.user.entity.UserInfo;
import com.atguigu.gmall.user.service.UserInfoService;
import com.atguigu.gmall.user.vo.LoginSuccessVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user/passport")
public class LoginController {
    @Autowired
    private UserInfoService  userInfoService;

    /**
     * 登录操作
     * @param userInfo
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody UserInfo userInfo){
        LoginSuccessVo  vo= userInfoService.login(userInfo);
        return  Result.ok(vo);
    }

    /**
     * 退出功能
     * 删除用户信息
     * @return
     */
    @GetMapping("/logout")
    public Result logout(@RequestHeader("token") String token){
         userInfoService.logout(token);
         return  Result.ok();
    }
}
